/****************************************************
	文件：BrightnessSaturationAndContrast.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/8/12 17:36:6
	功能：亮度、饱和度、对比度
*****************************************************/

using System;
using UnityEngine;

namespace RenderingPractice
{
    public class BrightnessSaturationAndContrast : PostEffectsBase
    {
        [Range(0.0f, 3.0f), Tooltip("亮度")]
        public float Brightness = 1.0f;
        [Range(0.0f, 3.0f), Tooltip("饱和度")]
        public float Saturation = 1.0f;
        [Range(0.0f, 3.0f), Tooltip("对比度")]
        public float Contrast = 1.0f;

        public Shader BrightnessSaturationContrastShader;
        private Material mBrightnessSaturationContrastMat;

        public Material Mat
        {
            get
            {
                mBrightnessSaturationContrastMat = CheckShaderAndCreateMaterial(BrightnessSaturationContrastShader, mBrightnessSaturationContrastMat);
                return mBrightnessSaturationContrastMat;
            }
        }

        private void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            if (Mat != null)
            {
                Mat.SetFloat("_Brightness", Brightness);
                Mat.SetFloat("_Saturation", Saturation);
                Mat.SetFloat("_Contrast", Contrast);
                Graphics.Blit(source, destination, Mat); //渲染后处理
            }
            else
            {
                Graphics.Blit(source, destination); //渲染原图像
            }
        }
    }
}
